import json
import time
import scrapy


class HkexSpider(scrapy.Spider):
    name = "HKEX"

    async def start(self):
        time_stamp  = int(time.time()*1000)
        yield scrapy.Request(
            f'https://www1.hkex.com.hk/hkexwidget/data/getequityfilter?lang=chn&token=evLtsLsBNAUVTPxtGqVeG7fEO1P55tyHyI5JjW00dGbeo6fQbGjxBIaItrSATJ0o&sort=5&order=0&all=1&qid=1762429710855&callback=jQuery35108422516987282684_{time_stamp}&_={time_stamp}')

    def parse(self, response):
        text = response.text[41:-1]
        data_json = json.loads(text)
        for data in data_json['data']['stocklist']:
            print(data['sym'],data['nm'],data['pc'],data['yld'])
